# coding: utf-8


# 审查机构表
unless DB.table_exists? (:manager)
  DB.create_table :manager do
    primary_key :id
    string :name
    string :state
  end
end


# 证件类型表
unless DB.table_exists? (:paper_type)
  DB.create_table :paper_type do
    primary_key :id
    string :name
    string :authority
    integer :cycle
    integer :delay
    string :state
  end
end


# 上岗持证要求表
unless DB.table_exists? (:paper_require)
  DB.create_table :paper_require do
    primary_key :id
    foreign_key :manager_id, :manager
    foreign_key :paper_type_id, :paper_type
    string      :position_id
  end
end


# 员工持证登记表
unless DB.table_exists? (:paper_register)
  DB.create_table :paper_register do
    primary_key :id
    foreign_key :paper_type_id, :paper_type
    string      :employee_id
    string      :paper_no
    date        :due_date
    string      :descr
    string      :state
  end
end


# 机构持证控制单位登记表
unless DB.table_exists? (:organ_register)
  DB.create_table :organ_register do
    primary_key :id
    foreign_key :manager_id, :manager
    string      :organ_id
  end
end











unless DB.table_exists? (:vehicle)
  DB.create_table :vehicle do
    primary_key :id
    foreign_key :vendor_id, :vendor
    string :number
    foreign_key :driver_id, :driver
    string :state
  end
end

unless DB.table_exists? (:schedule)
  DB.create_table :schedule do
    primary_key :id
    string :depart  #部门
    string :proposer #安全检查人员
    string :target #目的
    string :staff #人员
    datetime :from #出发时间
    datetime :to #结束时间
    string :phone #电话号码
    string :outset #开始时间
    string :through #经过地点
    string :arrivals #目的地
    number :amount #车辆数据
  end
end

unless DB.table_exists? (:schedule_vehicle)
  DB.create_table :schedule_vehicle do
    primary_key :id
    foreign_key :schedule_id, :schedule
    foreign_key :vehicle_id, :vehicle
  end
end
unless DB.table_exists? (:driver)
  DB.create_table :driver do
    primary_key :id
    string :name
    string :phone
  end
end
